import Cookies from 'js-cookie'
import { getAppEnvConfig } from '@/utils/env'

const getprefix = (): string => {
  const { VITE_GLOB_APP_SHORT_COOKIES } = getAppEnvConfig()
  return VITE_GLOB_APP_SHORT_COOKIES
}
const setCookie = (
  key: string,
  value: string,
  cookieAttr: Cookies.CookieAttributes
): string | undefined => {
  return Cookies.set(getprefix() + key, value, cookieAttr)
}

const getCookie = (key: string): string | undefined => {
  return Cookies.get(getprefix() + key)
}

const delCookie = (key: string, options?: Cookies.CookieAttributes): void => {
  Cookies.remove(getprefix() + key, options)
}

export const bwUtilsCookie = {
  setCookie,
  getCookie,
  delCookie,
}
